<template>
  <div>
    <el-button type="primary" style="margin:10px 0px 0px 20px;" @click="addEdit()">添加</el-button>
    <el-table :data="musicdata" style="width: 100%;margin: 10px auto 0" border
              v-loading="loading"
              element-loading-text="拼命加载中....">

      <el-table-column label="活动背景音乐" align="center" width="1200%" prop="name">
        
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="{row}">
          <el-button size="mini" type="primary" @click="handleEdit(row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="delEdit(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <edit ref="showEditDialog"/>
    <add-show ref="showAddDialog"/>
  </div>
</template>
<script>
import {getList,del} from '@/api/thk/cms/music'
import edit from './edit'
import addShow from './add'
export default {
  components:{
    edit,
    addShow
  },
  data(){
    return{
      loading:false,
      musicdata:[
        {
         name:'',
        }
      ]
    }
  },
  inject: ['reload'],
  methods:{
    handleEdit(row){
      console.log('handleEdit',row)
      this.$refs.showEditDialog.showEditDialog(row)
    },
    delEdit(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          del(this.$store.getters.token,row).then(res =>{
            if (res.data.status) {
                this.$message.success("删除成功");
                this.$emit("getList");
                this.showAddPageDialog = false;
              } else {
                this.$message.error("删除失败！原因：" + res.data.msg);
                this.$emit("getList");
              }
            this.reload()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    addEdit(){
      this.$refs.showAddDialog.showAddDialog(true)
    },
    getmusicList(){
        getList(this.$store.getters.token).then(res =>{
          this.musicdata = res.data.list.data
        },error => {
          console.log(error)
        })
    },
  },
  created() {
    this.getmusicList()
  },
}
</script>
<style>

</style>